#ifndef SUFFIXCALCULATOR_H
#define SUFFIXCALCULATOR_H

#include "Platform.h"
#include "ExprNode.h"
#include "OperatorTable.h"

class SuffixCalculator
{
public:
    static double Calculate(pLib::queue<ExprNode> expr)
    {
        pLib::stack<double> operateNumberStack;
        for(; !expr.empty(); expr.pop())
        {
            if(expr.front().type == ExprNode::Number)
            {
                operateNumberStack.push(expr.front().content.number_);
                continue;
            }
            if(expr.front().type == ExprNode::Operator)
            {
                double o1 = operateNumberStack.top();
                operateNumberStack.pop();
                double o2 = operateNumberStack.top();
                operateNumberStack.pop();
                auto operate = OperatorTable::Instance()->GetTable().find(expr.front().content.operator_)->second.active;
                operateNumberStack.push(operate(o2, o1));
                continue;
            }
        }
        return operateNumberStack.top();
    }
};


#endif //SUFFIXCALCULATOR_H
